cmake_minimum_required (VERSION 2.8)
project (Sagittarius)

#User Configuration
if(${WIN32})
    include( "UserConfigWin.txt" )
else()
    include( "UserConfigLinux.txt" )
endif()

#Options
if(LINK_WITH_LLVM)
    if(USE_LLVM_CONFIG)
        #add_definitions( -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS)
        message("${LLVMBinPath}/llvm-config")
        execute_process(COMMAND ${LLVMBinPath}/llvm-config --cppflags #x86 jit
            OUTPUT_VARIABLE LLVM_CXX_FLAGS)
            #Optional: RETURN_VALUE
        message("LLVM C++ Flags: " ${LLVM_CXX_FLAGS})
        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${LLVM_CXX_FLAGS}")

        #LLVM: run llvm-config to get compiling/linking options
        execute_process(COMMAND ${LLVMBinPath}/llvm-config --ldflags #x86 jit
            OUTPUT_VARIABLE LLVM_LINK_OPTIONS)
            #Optional: RETURN_VALUE
        message("LLVM LD Flags: " ${LLVM_LINK_OPTIONS})
        #link directories
        execute_process(COMMAND ${LLVMBinPath}/llvm-config --libdir
            OUTPUT_VARIABLE LLVM_LIB_DIR)
            #Optional: RETURN_VALUE
        message("LLVM Lib Dir: " ${LLVM_LIB_DIR})
        execute_process(COMMAND ${LLVMBinPath}/llvm-config --libs x86 jit
            OUTPUT_VARIABLE LLVM_LIBRARIES) 
            #Optional: RETURN_VALUE
        message("LLVM Libs: " ${LLVM_LIBRARIES})
    else()
        add_definitions( -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS)
        set(LLVM_LIB_DIR ${LLVMLibPath})
        set(LLVM_LIBRARIES LLVMJIT LLVMRuntimeDyld LLVMExecutionEngine LLVMX86AsmParser LLVMX86Disassembler LLVMX86CodeGen LLVMSelectionDAG LLVMAsmPrinter LLVMMCParser LLVMCodeGen LLVMScalarOpts LLVMInstCombine LLVMTransformUtils LLVMipa LLVMAnalysis LLVMX86Desc LLVMX86Info LLVMTarget LLVMX86AsmPrinter LLVMMC LLVMObject LLVMX86Utils LLVMCore LLVMSupport)
        # MCJIT
        set(LLVM_LIBRARIES ${LLVM_LIBRARIES} LLVMMCJIT LLVMRuntimeDyld)
    endif()
    
    include_directories(${LLVMIncludePath})
    include_directories(${LLVMGeneratedIncludePath})
    
    #Lib paths:
    link_directories(${LLVM_LIB_DIR})
    #Use LLVM link flags instead
    #CMake expects to receive the link directories separately. Too bad (scons is good in this situation, btw)
    #set(CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS} ${LLVM_LINK_OPTIONS})
endif()

if(LINK_WITH_GMP)
    link_directories(${GMPLibPath})
    include_directories(${GMPIncludePath})
endif()

if(ENABLE_LIBSBML)
    link_directories(${libSbmlPath})
    include_directories(${libSbmlIncludePath})
endif()

#App Paths
#find_program(flex_path flex ${FlexSearchPath})
#message("Path to flex = " ${flex_path})

#add include directories
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
include_directories(${CMAKE_CURRENT_BINARY_DIR}) #we have to do this to get the generated header

#link_directories(${CMAKE_CURRENT_BINARY_DIR}/lib)

message("libSbmlPath = ${libSbmlPath}")
message("libSbmlIncludePath = ${libSbmlIncludePath}")

add_subdirectory(sagittarius)

add_subdirectory(sandbox)

#generated lexers
#unsub
#add_custom_command(OUTPUT unsub.c COMMAND ${flex_path} ${FlexOutfileOpt}unsub.c ${CMAKE_CURRENT_SOURCE_DIR}/src/unsub.l)
#add_custom_target(unsub ALL DEPENDS unsub.c)

#lc_counter
#add_custom_command(OUTPUT lc_counter.c COMMAND ${flex_path} ${FlexOutfileOpt}lc_counter.c ${CMAKE_CURRENT_SOURCE_DIR}/src/lc_counter.l DEPENDS src/lc_counter.l)
#add_custom_target(lc_countert ALL DEPENDS lc_counter.c) #src/lc_counter.l)

#add_executable(basic src/basic.c)
#add_executable(lc_counter lc_counter.c)